package com.fjt.book_pay.dao;


import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.fjt.book_pay.pojo.P_User;

public interface P_UserDao {
	@Results({
		@Result(property = "pay_name", column = "pay_name"),
		@Result(property = "pay_password", column = "pay_password"),
		@Result(property = "pay_email", column = "pay_email"),
		@Result(property = "pay_phone", column = "pay_phone"),
		@Result(property = "pay_money", column = "pay_money"),
		@Result(property = "bank_number", column = "bank_number")}
	)
	
	@Select("Select * from p_user where pay_name=#{pay_name}")
	public P_User findUserInfoByName(P_User p_User);
	
	@Select("Select email from p_user where pay_name=#{pay_name}")
	public P_User findEmailByName(P_User p_User);
	
	@Select("Select * from p_user where pay_name=#{pay_name} and pay_password=#{pay_password}")
	public P_User validateUser(P_User p_User);
	
	@Insert("Insert into p_user VALUES(#{pay_name},#{pay_password},#{pay_email},#{pay_phone},#{bank_number},#{pay_money})")
	public boolean addUser(P_User p_user);
	
	@Update("update p_user set pay_password=#{pay_newpwd} where pay_name=#{pay_name} and pay_password=#{pay_oldpwd}")
	public boolean modifyPassword(P_User user);
	
	@Update("update p_user set pay_password=#{pay_password} where pay_email=#{pay_email}")
	public boolean resetPassword(P_User user);
	@Update("update p_user set pay_money=pay_money+#{money} where pay_name=#{pay_name}")
	public boolean addPayMoney(@Param("pay_name") String pay_name,@Param("money") int money);
	
	@Update("update p_user set pay_money=pay_money-#{money} where pay_name=#{pay_name} and pay_password=#{password}")
	public boolean subPayMoney(@Param("pay_name") String pay_name,@Param("password") String password,@Param("money") int money);
		
	@Update("update p_user set pay_email=#{pay_email},pay_phone=#{pay_phone}"
			+ ",bank_number=#{bank_number} "
			+ "where pay_name=#{oldname}")
	public boolean modifyUserInfo(
			@Param("pay_email") String pay_email,@Param("pay_phone") String pay_phone,@Param("bank_number") int bank_number,
			@Param("oldname") String oldname);
	//	public boolean validate(User user);
//	public User findUserByEmail(String email);
//	public void modifyPassword(User user);
	
	@Select("select pay_money from p_user where pay_name=#{pay_name}")
	public int checkPaymoney(P_User user);
	
	@Select("select bank_number from p_user where pay_name=#{pay_name}")
	public int findUserBank(P_User user);
	
	@Select("select payname from user where username=#{username}")
	public String findPaynameByUsername(String username);
	
}
